<template>
  <div>
    <el-dialog :title='option.title' :visible.sync='isShow' width="770px" @open="openCreate"
      :close-on-click-modal="false" center>
      <div v-loading="loading">
        <div >
          <el-card>
            <el-form size="mini" ref="form" :model="form"  label-width="110px" :rules="rulesBase"
              label-position="left">
              <el-row :gutter="30">
                <el-col :span="12">
                  <el-form-item prop="PARAMDESC" label="六维元素名称：">
                    <el-input v-model="form.PARAMDESC" placeholder="六维元素名称" :disabled="option.isChecked"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="PARAMVALUE" label="目标值：">
                    <el-input v-model="form.PARAMVALUE" placeholder="请输入目标值" ></el-input>
                  </el-form-item>
                </el-col>
                </el-row>
            </el-form>
          </el-card>
          <div style="text-align:center;margin-top:20px">
            <el-button size="mini" @click="addType">取消</el-button> 
            <el-button type="primary" size="mini"  @click="add" >确认</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/common/utils/request";
import toolBox from "@/common/utils/toolBox";
import getGlobalParams from "@/common/utils/getGlobalParams";
import request1 from "@/common/utils/requestYg";
import mod from "@/message/siteManagement/eleArrManage/query";

export default {
  name: "",
  data() {
    return {
      loading: false,
      brnoList: [],
      currentPage: 1, //当前页
      form: {
        PARAMDESC:"",
        PARAMVALUE:"",
      },
      rulesBase: {
      },
    };
  },
  props: {
    //父元素传递的数据
    option: Object
  },
  components: {},
  computed: {
    isShow: {
      //创建用户弹窗是否显示
      get: function() {
        return this.option.isShow;
      },
      set: function(newValue) {
        this.option.isShow = newValue;
      }
    }
  },
  created: function() {
  },
  methods: {
    add() {
      //添加
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          let resBody = new mod();
          resBody.data.PARAMDESC = this.form.PARAMDESC;
          resBody.data.PARAMVALUE = this.form.PARAMVALUE;
          resBody.data.oper_type = "U";
          request1(resBody)
            .then(response => {
              if (response.SYS_HEAD.ReturnCode === "000000") {
                this.$emit("refreshTable");
                this.$message({
                  type: "success",
                  message: `维护${response.SYS_HEAD.ReturnMessage}!`
                });
                this.isShow = false;
              } else {
                this.$message({
                  type: "error",
                  message: `${response.SYS_HEAD.ReturnMessage}!`
                });
              }
              this.loading = false;
            })
            .catch(error => {
              this.loading = false;
            });
        } else {
          this.$message({
            type: "warning",
            message: "请输入合法的数据！"
          });
          return false;
        }
      });
    },
    openCreate() {
      //打开弹窗事件
      this.loading = true;
      if (this.$refs.form) {
        this.$refs["form"].resetFields(); //清楚表单验证
      }
      this.$nextTick(function() {
        if (this.option.log == "2") {
          this.updateDate();
        }else{
        }
      });
      this.loading = false;
    },
    updateDate() {
      this.form.PARAMDESC = this.option.currentRow.PARAMDESC;
      this.form.PARAMVALUE = this.option.currentRow.PARAMVALUE;
    },
    addType() {
      //关闭弹窗事件，清除表单验证
      this.option.isShow = false;
      this.$refs["form"].clearValidate();
    },
  }
};
</script>
<style lang="scss" scoped>
</style>
